package com.wc.alorithm_blue_bridge._思维.Q3272;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * @Author congge
 * @Date 2023/11/22 10:12
 * @description 小蓝的漆房
 * https://www.lanqiao.cn/problems/3272/learning/?page=1&first_category_id=1
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            int[] array = new int[n];
            int ans = Integer.MAX_VALUE;
            Set<Integer> set = new HashSet<>();
            for (int i = 0; i < n; i++) {
                int num = sc.nextInt();
                set.add(num);
                array[i] = num;
            }
            for (int num : set) {
                int tmpAns = 0;
                for (int i = 0; i < n; i++) {
                    if (array[i] != num) {
                        tmpAns++;
                        // -1 因为上面的i++;
                        i += k - 1;
                    }
                }
                ans = Math.min(tmpAns, ans);
            }

            System.out.println(ans);
        }
    }
}
